require('./page.css');
let cp = require('cp');
cp.checkToken(cp.getCookie('token'));
let vm_org_new = avalon.define({
  $id: 'mc_new_organization',
  organization_name: '',
  validate: {
    onValidateAll: function(reasons) {
      if (reasons.length) {
        cp.layerMsg({msg: reasons[0].getMessage()});
      } else {
        cp.ajaxUrl({
          controller: 'orgacs',
          cmd: 'com.rel.porg.pb.org_info_req',
          data: {
            req: 0,
            info: {
              title: vm_org_new.organization_name,
            },
          },
          success: function(res) {
            cp.setCookie('token', res.token, 12);
            const libs = require('libs');
            libs.sendParamBetweenPages('common', 'orgid', res.orgid);
            window.location.href = cp.PAGE_ROOT + 'index/index/page.html';
          },
        });
      };
    },
  },
});
